﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MForm;
using ORMapping;
using BLL;
using PublicCommon;

namespace ModifyDataMoudle.Integration
{
    public partial class IntegrationQueryForm : MdiForm
    {
        private TBLCardTypeBLL tctb = new TBLCardTypeBLL();
        public IntegrationQueryForm(Parent im) : base(im)
        {
            InitializeComponent();
            IList<TBLCardType> ilSource = tctb.GetAllCardTypes();
            ilSource.Insert(0, new TBLCardType { CardType = string.Empty, CardName = string.Empty });
            TBLCardType_CardType.DataSource = ilSource;
            Card_Valid.DataSource = YNStatesInstance.DataSource;
            MemberInfo_Sex.DataSource = SexStatesInstance.DataSource;
        }

        public override void Query()
        {
            CardBLL cdb = new CardBLL();
            Card cd = cdb.QueryCardByNO(Card_CardNO.Text);
            if (cd == null)
            {
                MessageBox.Show(String.Format("查询不到{0}攀岩卡", Card_CardNO.Text));
                return;
            }

            Functions.SetControlTextFromObject<Card>(this.Controls, cd);
            Functions.SetPictureBox(MemberInfo_Photo, cd.MemberID.GetPhoto());

            if(Functions.HasCardWarning(cd.StartDate,cd.EndDate))
            {
                MessageBox.Show("该卡快过期了","警告",MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (Functions.HasCardVaild(cd.StartDate, cd.EndDate))
            {
                MessageBox.Show("该卡已经过期了","过期",  MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
